package com.sx.zongzhi.presenter;

import android.content.Context;

import com.google.gson.Gson;
import com.sx.zongzhi.bean.PhotoBean;
import com.sx.zongzhi.bean.WorkLogBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.modle.HeadParamBean;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.AddOrUpdateWorkLog;

import java.util.List;
import java.util.Map;

/**添加 修改工作日志
 * Created by admin on 2017/12/6.
 */

public class AddOrUpdateWorkLogPest {
    private AddOrUpdateWorkLog addOrUpdateWorkLog;

    public AddOrUpdateWorkLogPest(AddOrUpdateWorkLog addOrUpdateWorkLog) {
        this.addOrUpdateWorkLog = addOrUpdateWorkLog;
    }
    //添加工作日志
    public void addWorkLog(Context context, String title, String workContent, int addWorkDiaryCode,
                           List<PhotoBean> fileList){
        Map<String,Object> map = HeadParamBean.getHead(context);
        map.put("workDiary.title", title);
        map.put("workDiary.workContent", workContent);
        map.put("workDiary.addWorkDiaryCode", addWorkDiaryCode);
        if (fileList != null && fileList.size() > 0){
            for (int i=0;i<fileList.size();i++){
                map.put("workDiary.files["+i+"].path",fileList.get(i).getPath());
                map.put("workDiary.files["+i+"].suffixType",fileList.get(i).getSuffixType());
            }
        }
        new ApiManager().addWorkLog(map, new BaseCallBack<BaseResult<WorkLogBean>>() {
            @Override
            public void onSuccess(BaseResult<WorkLogBean> response) {
                addOrUpdateWorkLog.AddOrUpdateWorkLogSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                addOrUpdateWorkLog.showError(message);
            }
        });
    }
    //修改工作日志
    public void updateWorkLog(Context context,String id, String title, String workContent,
                              int addWorkDiaryCode, List<PhotoBean> fileList,
                              List<String> removeIds){
        Map<String,Object> map = HeadParamBean.getHead(context);
        map.put("workDiary.id", id);
        map.put("workDiary.title", title);
        map.put("workDiary.workContent", workContent);
        map.put("workDiary.addWorkDiaryCode", addWorkDiaryCode);
        for (int i = 0 ; i < removeIds.size() ; i ++){
            map.put("workDiary.removeId["+ i +"]",removeIds.get(i));
        }
        if (fileList != null && fileList.size() > 0){
            for (int i=0;i<fileList.size();i++){
                map.put("workDiary.files["+i+"].path",fileList.get(i).getPath());
                map.put("workDiary.files["+i+"].suffixType",fileList.get(i).getSuffixType());
            }
        }
        new ApiManager().updateWorkLog(map, new BaseCallBack<BaseResult<WorkLogBean>>() {
            @Override
            public void onSuccess(BaseResult<WorkLogBean> response) {
                addOrUpdateWorkLog.AddOrUpdateWorkLogSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                addOrUpdateWorkLog.showError(message);
            }
        });
    }
}
